package grape.auth.rest.service.impl;

import grape.base.rest.client.user.UserClient;
import grape.base.service.user.dto.UserInnerDetailDto;
import grape.base.service.user.po.UserIdentifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * 仅根据用户 id 查询
 * Created by yangwei
 * Created at 2020/1/8 17:39
 */
@Component("userDetailsService")
public class UserDetailsServiceImpl extends BaseUserDetailsServiceImpl {

    @Autowired
    private UserClient userClient;

    @Override
    public UserIdentifier.TypeDictItem getType() {
        throw new RuntimeException("not support getType method");
    }

    @Override
    public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
        UserInnerDetailDto details = userClient.detailsById(userId);
        return wrapperUserDetails(details);
    }
}
